package com.example.petplanet.controller;

import com.example.petplanet.result.Result;
import com.example.petplanet.service.UserService;
import com.example.petplanet.util.TLUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/user")
public class UserController {


    //用户登出点赞信息同步未测试
    //keys换成scan方法

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/LoginByPhone")
    public Result<Object> LoginByPhone(@RequestParam String phone,
                                       @RequestParam String code){
        return userService.LoginByPhone(phone,code);
    }

    @PostMapping("/LoginOut")
    public Result<Object> LoginOut(){
        return userService.LoginOut();
    }


    @GetMapping("/getBasicMessage")
    public Result<Object> getBasicMessage(){
        return userService.getBasicMessage();
    }



    @PostMapping("/editBasicMessage")
    public Result<Object> editBasicMessage(@RequestParam char sex,
                                           @RequestParam Integer age,
                                           @RequestParam String name){
        return userService.editBasicMessage(sex,age,name);
    }


    @PostMapping("/uploadAvatar")
    public Result<Object> uploadAvatar(@RequestBody MultipartFile file){
        return userService.uploadAvatar(file);
    }

    @PostMapping("/test")
    public Result<Object> Test(){
        System.out.println("user:"+TLUtil.getUser());
        System.out.println("userid:"+TLUtil.getUserId());
        return Result.success();
    }

    @GetMapping("/stsToken")
    public Result<Object> stsToken(){
        return userService.stsToken();
    }

    //关注和取消关注的接口，redis的user对象储存着用户关注的id，定时任务同步到mysql,登录时再引入follow和fans集合
    @PostMapping("/follow")
    public Result<Object> followUser(@RequestParam Long targetUserId) {
        return userService.followUser(targetUserId);
    }


    @DeleteMapping("/cancelFollow")
    public Result<Object> cancelFollow(@RequestParam Long targetUserId) {
        return userService.cancelFollow(targetUserId);
    }

    @GetMapping("/getUserBasicMessage")
    public Result<Object> getUserBasicMessage(@RequestParam Long targetUserId) {
        return userService.getUserBasicMessage(targetUserId);
    }

    @PostMapping("/changeBind")
    public Result<Object> changeBind(@RequestParam String phone, @RequestParam String code) {
        return userService.changeBind(phone, code);
    }


    @PostMapping("/verifyOldPhone")
    public Result<Object> verifyOldPhone(@RequestParam String code) {
        return userService.verifyOldPhone(code);
    }


    //阿里云签名未获取，无法发送
    @PostMapping("/sendPhoneCode")
    public Result<Object> sendPhoneCode(@RequestParam String phone) {
        return userService.sendPhoneCode(phone);
    }


}
